package com.self.cgqcompose.mock

import android.content.Context
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.self.cgqcompose.R
import com.self.cgqcompose.beans.Area9Bean
import com.self.cgqcompose.beans.BottomTabs
import com.self.cgqcompose.beans.HomeTopTabs

class MockJson {
    companion object {
        fun loadMockDataBottomTabs(context: Context): BottomTabs {
            val inputStream = context.resources.openRawResource(R.raw.bottom_tabs)
            val jsonString = inputStream.bufferedReader().use { it.readText() }
            val type = object : TypeToken<BottomTabs>() {}.type
            return Gson().fromJson(jsonString, type)
        }

        fun loadMockDataTopTabs(context: Context): HomeTopTabs {
            val inputStream = context.resources.openRawResource(R.raw.home_top_tabs)
            val jsonString = inputStream.bufferedReader().use { it.readText() }
            val type = object : TypeToken<HomeTopTabs>() {}.type
            return Gson().fromJson(jsonString, type)
        }

        fun loadMockDataArea9(context: Context): Area9Bean {
            val inputStream = context.resources.openRawResource(R.raw.area_code_9)
            val jsonString = inputStream.bufferedReader().use { it.readText() }
            val type = object : TypeToken<Area9Bean>() {}.type
            return Gson().fromJson(jsonString, type)
        }
    }
}